home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group01b.txt / 000142_icon-group-sender_Thu Sep 13 12:32:09 2001.msg < prev    next >
Internet Message Format  |  2002-01-03  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id f8DJUsE26090
  4.     for icon-group-addresses; Thu, 13 Sep 2001 12:30:54 -0700 (MST)
  5. Message-Id: <200109131930.f8DJUsE26090@baskerville.CS.Arizona.EDU>
  6. From: Steve Wampler <swampler@noao.edu>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: join
  9. Date: Thu, 13 Sep 2001 08:41:15 -0700
  10. X-Complaints-To: abuse@noao.edu
  11. X-Accept-Language: en
  12. To: icon-group@cs.arizona.edu
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14. Status: RO
  15. Content-Length: 2114
  16.  
  17. Andrew Hamm wrote:
  18. > Steve Wampler wrote in message <3B97AB3B.12DBFBEE@noao.edu>...
  19. > >
  20. > >A question for people: How equivalent are the following approaches?
  21. > >
  22. > >    f := open(filename)
  23. > >    while line := read(f) do ...
  24. > >    close(f)
  25. > >
  26. > >and
  27. > >
  28. > >    cf := create (!(f := open(filename)) | (close(f),&fail))
  29. > >    while line := @cf do ...
  30. > >
  31. > OK - I'll bite. Is this going to be another trick question like comparing
  32. >     while expr
  33. > with some sort of generator in the implementation book? can't remember the
  34. > alternatives, and my book is at home.
  35.  
  36. Well, it wasn't planned that way, but probably someone with more detailed
  37. knowledge of the implementation can find a number of differences at that
  38. level!
  39.  
  40. > Anyways, ignoring the lack of error checking, all I can see is that cf is
  41. > restartable to repoen the file. Depending on the scope of f, it could be
  42. > private to the coexpression and therefore inaccessible.
  43. > What am I missing?
  44.  
  45. I don't think you're missing anything.  Here are the things I see as
  46. "different" (others will no doubt disagree!):
  47.  
  48. (1) scope of f affects behavior. Just as Andrew says, if f is local when
  49.     the coexpression is created, then it's inaccessible outside the
  50.     coexpression.  Why is this a difference?  Because it means...
  51.  
  52. (2) if you break out of the loop early in the first example, you can still
  53.     close the file.  if you break out of the loop early in the second (and
  54.     f is inaccessible), the only way to close the file is to exhaust the
  55.     co-expression, via (say)
  56.  
  57.         while @cf
  58.  
  59.     which could be a significant performance hit, but...
  60.  
  61. (3) the coexpression version provides automatic closing of the file when you're
  62.     done reading it.  In the first approach, if you forget the close(f) after
  63.     the while, the file remains open.
  64.  
  65. (4) What happens if you refresh the co-expression before it "finishes"?  (Ok,
  66.     this probably isn't a real difference, but is more likely to sneak up on you
  67.     than doing the equivalent in the first case...)
  68.  
  69.  
  70.  
  71. --
  72. Steve Wampler-  SOLIS Project, National Solar Observatory
  73. swampler@noao.edu
  74.